val input = TextIO.openIn("input.txt");

fun printInt (a:int) =
    print(Int.toString(a)^" ");

fun getInt () =
    Option.valOf (TextIO.scanStream (Int.scan StringCvt.DEC) input);
    
fun printIntList ( [] ) = ()
  | printIntList ( x::xs ) = 
    let
	val tmp = printInt(x)
    in
	printIntList(xs)
    end;

fun getIntList ( 0 ) = []
  | getIntList ( N:int) = getInt()::getIntList(N-1);

fun split [ ]  = ([ ], [ ]) 
    | split [x] = ([ ], [x])
    | split (x::y::L) =
	let val (A, B) =split L
	in (x::A, y::B) 	
	end;

datatype tree = Empty | Br of tree * int * tree; 
fun trav(Br(t1,a,t2)) = trav(t1)@(a::trav(t2))
    |trav empty = [];
(*BEGIN*)
fun listToTree ([] : int list) : tree = Empty
  | listToTree (x::l) = 
    let
        val (L1, L2) = split(l)
    in
        Br(listToTree L1, x, listToTree L2)
    end;
(*END*)
val L = getIntList(7);
printIntList (trav(listToTree L));